﻿using AuthCenter.Domain;
using AuthCenter.ErorCode;
using AuthCenter.Infrastructure;
using AuthCenter_API.Read.Applications.Commands.RBAC;
using MediatR;
using System.Runtime.InteropServices;

namespace AuthCenter_API.Read.Applications.CommandHandlers.RBAC
{
    public class FantianRoleMenuCommandHandler : IRequestHandler<FantianRoleMenuCommand, APIResult<object>>
    {
        private readonly IBaseRepository<RoleMenuModel> _roleMenuRepository;

        public FantianRoleMenuCommandHandler(IBaseRepository<RoleMenuModel> roleMenuRepository)
        {
            _roleMenuRepository = roleMenuRepository;
        }

        public Task<APIResult<object>> Handle(FantianRoleMenuCommand request, CancellationToken cancellationToken)
        {
            APIResult<object> result = new APIResult<object>();
            List<int> Menuid = _roleMenuRepository.GetAll().Where(x => x.RID == request.RoleId).Select(x => x.MID).ToList();
            result.Data = Menuid;
            return Task.FromResult(result);
        }
    }
}
